<template>
	<view class="goods-card" :class="classes" @click="navToGoodsDetail(goods)">
		<view class="goods-card-cover">
			<image :src="goods.goodsCover" />
		</view>
		<view class="goods-card-info">
			<text class="goods-name">{{ goods.goodsName }}</text>
			<view class="bage-warp">
				<view class="bage new" v-if="goods.isHot">热门</view>
				<view class="bage hot" v-if="goods.isNew">新品</view>
			</view>
			<view class="goods-card-info__btm">
				<text class="goods-amount"><text class="goods-amount-character">￥</text>{{ roundToDecimal(goods.price,2) }}</text>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { computed } from "vue";
	import { nav,roundToDecimal } from "@/libs/utils"

	const props = defineProps({
		type: {
			type: String,
			default: "col",
		},
		goods: {
			type: Object,
			default: () => { },
		},
		totalCount: Number,
		totalLike: Boolean,
	});

	let classes = computed(() => {
		let res = "";
		if (props.type) {
			res += ` goods-card--${props.type}`;
		}
		if (props.totalLike) {
			res += " goods-card--total-like";
		}
		return res;
	});
	// 跳转到详情
	const navToGoodsDetail = (goods : any) => {
		nav(`/subpackage/goods/pages/detail/index?id=${goods.goodsId}`, "");
	};
</script>

<style lang="less" scoped>
	.goods-card {
		background: #fff;
		border-radius: 10rpx;
		overflow: hidden;

		&--col {
			.goods-card-cover {
				width: 100%;
				height: 320rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}

			.goods-card-info {
				font-size: 0;
				padding: 18rpx;
				box-sizing: border-box;

				&__btm {
					padding-top: 25rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
			}
		}

		&--row {
			display: flex;
			padding: 10rpx;
			box-sizing: border-box;

			.goods-card-cover {
				width: 280rpx;
				height: 280rpx;
			}

			.goods-card-info {
				display: flex;
				flex-direction: column;
				flex: 1;
				padding: 20rpx 23rpx;
				box-sizing: border-box;

				&__btm {
					padding-top: 25rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
			}

			&.goods-card--total-like {
				.goods-card-info {
					padding: 0 11rpx 0 20rpx;
					box-sizing: border-box;

					&__btm {
						padding-top: 10rpx;
						flex-wrap: wrap;
					}
				}

				.goods-amount {
					width: 100%;
				}

				.goods-like {
					display: flex;
					align-items: center;
					width: 100%;
				}
			}
		}
		.bage-warp{
			height: 40rpx;
			display: flex;
			align-items: center;
			justify-self: flex-start;
    		flex-wrap: wrap;
			.bage {
				border-radius: 6rpx;
				font-size: 20rpx;
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				border-width: 1rpx;
				border-style: solid;
				font-weight: normal;
				display: inline;
				padding: 5rpx 8rpx;
				margin-right: 10rpx;
				font-weight: normal;
			}
			.new{
				background: #ECFFE7;
				border-color: #23AB04;
				color: #23AB04
			}
			.hot{
				background: #FFFFFF;
				border-color: #fc3247;
				color: #fc3247
			}
		}

		.goods-name {
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			overflow: hidden;
			font-size: 28rpx;
			font-weight: 500;
			color: #333;
			line-height: 40rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			word-break: break-all;
		}

		.goods-keys {
			width: 310rpx;
			margin-top: 20rpx;
			font-size: 26rpx;
			font-weight: 500;
			color: #999;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.goods-like {
			&-count {
				margin-right: 31rpx;
				flex: 1;
				text-align: right;
				font-size: 26rpx;
				font-weight: 500;
				color: #999;
			}

			&-img {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.goods-amount {
			font-size: 36rpx;
			font-weight: bold;
			color: #fc3247;
		}

		.goods-amount-character {
			font-size: 30rpx;
			font-weight: initial;
		}

		.rise {
			font-size: 24rpx;
		}
	}
</style>